/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mp3tagger;

import entagged.audioformats.AudioFile;
import entagged.audioformats.AudioFileIO;
import entagged.audioformats.Tag;
import entagged.audioformats.exceptions.CannotReadException;
import java.io.File;

/**
 *
 * @author Rajab
 */
public class ListItem {

    private File file;
    private Tag tag;
    private AudioFile mp3;
    private boolean _isRead = false;

    public boolean isRead() {
        return _isRead;
    }

    public ListItem(File file) {
        this.file = file;
    }

    private String getFormattedInfo() {
        if (!tag.isEmpty()) {
            return String.format("%s - %s", tag.getFirstArtist(), tag.getFirstTitle());
        } else {
            return file.getName();
        }
    }

    public void read() throws CannotReadException {
        mp3 = AudioFileIO.read(file);
        
        tag = mp3.getTag();
        _isRead = true;
    }

    public File getFile() {
        return file;
    }

    @Override
    public String toString() {
        if (!_isRead) {
            return file.getName();
        } else {
            return getFormattedInfo();
        }


    }
}
